<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>物品领用审批表列表</title>
	<#include "/common/resource.ftl">
</head>
<body>

<div class="ui-operation">
    <div class="ui-search-items layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">申请人</label>
                <div class="layui-input-inline">
                    <input type="text" name="createName" class="layui-input">
                </div>
            </div>
            <#--<div class="layui-inline">
                <label class="layui-form-label">验证日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">验证链接</label>
                <div class="layui-input-inline">
                    <input type="tel" name="url" class="layui-input">
                </div>
            </div>-->
        </div>
    </div>
    <div class="ui-buttons">
        <div class="layui-btn-group tools">
            <#--<@auth code='goodsUseApproval_add'><button class="layui-btn layui-btn-normal open-dialog" p="url:'${params.contextPath}/view/business/goodsUseApproval/goodsUseApproval_edit.htm',title:'添加物品领用审批表',width:'600px',height:'400px'"><i class="fa fa-plus"></i>添加</button></@auth>
            <@auth code='goodsUseApproval_update'><button class="layui-btn layui-btn-normal singleSelected" p="url:'${params.contextPath}/view/business/goodsUseApproval/goodsUseApproval_edit.htm',title:'编辑物品领用审批表',width:'600px',height:'400px'"><i class="fa fa-pencil"></i>修改</button></@auth>
            <@auth code='goodsUseApproval_delete'><button class="layui-btn layui-btn-normal remove-button" reurl="${params.contextPath}/web/goodsUseApproval/delete.json"><i class="fa fa-remove"></i>删除</button></@auth>-->
            <button class="layui-btn layui-btn-normal accept-button" reurl="${params.contextPath}/web/goodsUseApproval/accept.json"><i class="fa fa-pencil"></i>发放</button>
        </div>
        <div class="ui-searchs">
            <#--<div class="value"><input type="text" name="name" value="" placeholder="名称"/></div>-->
            <input type="button" value="搜索" class="layui-btn layui-btn-danger search-button"/>
        </div>
    </div>
</div>
<div class="ui-content" style="padding-left: 10px;padding-right:10px;">
    <table id="datagrid" options="url:'${params.contextPath}/web/goodsUseApproval/list.json',params:'getSearchParams',dblClickRow:'showDetail'">
        <thead>
			<tr>
				<th data-options="field:'id',checkbox:true"></th>
                <th data-options="field:'createName',width:150,align:'left'">申请人</th>
				<th data-options="field:'reason',width:100,align:'left'">事由</th>
				<th data-options="field:'name',width:100,align:'left'">物品名称</th>
				<th data-options="field:'quantity',width:100,align:'left'">领用数量</th>
				<th data-options="field:'dept',width:100,align:'left'">部门</th>
				<th data-options="field:'happenDateStr',width:120,align:'left'">日期</th>
                <th data-options="field:'validStatusStr',width:150,align:'left',formatter:formatValidState">审核状态</th>
                <th data-options="field:'statusStr',width:150,align:'left',formatter:formatState">发放状态</th>
				<th data-options="field:'remark',width:100,align:'left'">备注</th>
			</tr>
        </thead>
    </table>
</div>
<script type="text/javascript">
    function getSearchParams() {
        return {createName: $("input[name='createName']").val()};
    }
    var showDetail = function (index, row) {
        var url = "${params.contextPath}/view/business/goodsUseApproval/goodsUseApproval_detail.htm?his=1&id=" + row.id + "&formId=" + row.id;
        DialogManager.openDialog("url:'" + url + "',title:'物品领用审批表详情',width:'600px',height:'600px'");
    };

    function formatState(row) {
        if (row.status == 2) {
            return '<span class="ui-accept">' + row.statusStr + '</span>';
        } else if (row.status == 1) {
            return '<span class="ui-stop">' + row.statusStr + '</span>';
        }
        return row.statusStr;
    }

    function formatValidState(row) {
        if (row.validStatus == 2) {
            return '<span class="ui-accept">' + row.validStatusStr + '</span>';
        } else if (row.validStatus == 3) {
            return '<span class="ui-stop">' + row.validStatusStr + '</span>';
        }
        return row.validStatusStr;
    }

    $(function () {
        /*$(".remove-button").click(function () {
            var ids = DataGrid.getCheckedIds();
            if (ids == "") {
                layer.msg("请选择删除记录")
                return false;
            }
            var url = $(this).attr("reurl");
            layer.confirm('确定删除记录', function () {
                $.ajaxRequest({
                    type: 'post',
                    url: url,
                    data: {ids: ids.join(",")},
                    success: function (data) {
                        $.message(data.message);
                        if (data.success) {
                            DataGrid.reload();
                        }
                    }
                });
            });
        });*/
        $(".accept-button").click(function () {
            var row = DataGrid.getSelectRow();
            if (!row) {
                $.message("请选择需要发放的记录");
                return false;
            }
            if (row.status == 2) {
                $.message("已发放记录无法重新发放");
                return false;
            }
            if (row.validStatus != 2) {
                $.message("未审核通过记录无法发放");
                return false;
            }
            var url = $(this).attr("reurl");
            $.ajaxRequest({
                type: 'post',
                url: url,
                data: {id: row.id},
                success: function (data) {
                    $.message(data.message);
                    if (data.success) {
                        DataGrid.reload();
                    }
                }
            });
        });
    });
</script>
</body>

</html>
